package com.esri.core.symbol.advanced;

import android.graphics.Bitmap;
import android.util.Log;
import com.esri.core.internal.util.d;
import com.esri.core.symbol.advanced.SymbolDictionary;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
class SymbolDictionaryImpl {
    long a;
    private SymbolDictionary.DictionaryType b;
    private List<String> c = new ArrayList();
    private Map<String, List<String>> d = new HashMap();

    private static native long nativeCreateDictionary(String str, String str2);

    private native String[] nativeFindSymbols(long j, String str);

    private native String nativeGetMetadata(long j);

    private static native boolean nativeGetSymbolImage(String str, String str2, Bitmap bitmap);

    private native String nativeGetSymbolProperties(String str, String str2);

    private static native void nativeReleaseDictionary(long j);

    public SymbolDictionaryImpl(SymbolDictionary.DictionaryType dictionaryType, String str) {
        this.b = dictionaryType;
        long nativeCreateDictionary = nativeCreateDictionary(dictionaryType.toString(), str);
        this.a = nativeCreateDictionary;
        try {
            a(d.c(nativeGetMetadata(nativeCreateDictionary)));
        } catch (Exception e) {
            Log.w("SymbolDictionary", "Symbol dictionary fails to retrieve meta daya" + e);
        }
    }

    public List<String> a() {
        return this.c;
    }

    public Map<String, List<String>> b() {
        return this.d;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public String a(String str) {
        return nativeGetSymbolProperties(this.b.toString(), str);
    }

    public List<SymbolProperties> a(List<String> list, Map<String, List<String>> map) {
        StringWriter stringWriter = new StringWriter();
        try {
            JsonGenerator a = d.a(stringWriter);
            a.writeStartObject();
            a.writeArrayFieldStart("keywords");
            if (list != null) {
                for (String str : list) {
                    a.writeString(str);
                }
            }
            a.writeEndArray();
            a.writeArrayFieldStart("filters");
            if (map != null) {
                for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                    for (String str2 : entry.getValue()) {
                        a.writeStartObject();
                        a.writeStringField(entry.getKey(), str2);
                        a.writeEndObject();
                    }
                }
            }
            a.writeEndArray();
            a.writeEndObject();
            a.close();
            ArrayList arrayList = new ArrayList();
            String[] nativeFindSymbols = nativeFindSymbols(this.a, stringWriter.toString());
            if (nativeFindSymbols != null && nativeFindSymbols.length != 0) {
                for (String str3 : nativeFindSymbols) {
                    arrayList.add(new SymbolProperties(str3, this));
                }
                return arrayList;
            }
        } catch (IOException unused) {
        }
        return null;
    }

    protected void finalize() throws Throwable {
        super.finalize();
        long j = this.a;
        if (j == 0) {
            return;
        }
        nativeReleaseDictionary(j);
    }

    private void a(JsonParser jsonParser) throws JsonParseException, IOException, Exception {
        if (jsonParser == null || !d.c(jsonParser)) {
            return;
        }
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if ("filters".equals(currentName)) {
                if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        jsonParser.nextToken();
                        String currentName2 = jsonParser.getCurrentName();
                        ArrayList arrayList = new ArrayList();
                        jsonParser.nextToken();
                        if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                arrayList.add(jsonParser.getText());
                            }
                        }
                        this.d.put(currentName2, arrayList);
                        jsonParser.nextToken();
                    }
                }
            } else if ("keywords".equals(currentName)) {
                if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        this.c.add(jsonParser.getText());
                    }
                }
            } else {
                jsonParser.skipChildren();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean a(String str, Bitmap bitmap) {
        return nativeGetSymbolImage(this.b.toString(), str, bitmap);
    }
}
